package com.laot.searchManage.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.laot.searchManage.utils.UserUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.laot.seacher_master.model.common.BaseResponse;
import org.laot.seacher_master.model.common.PageRequest;
import org.laot.seacher_master.model.common.ResultUtils;
import org.laot.seacher_master.model.entity.User;
import org.laot.searchManage.dto.DatasourceApplicationApproveDto;
import org.laot.searchManage.dto.DatasourceApplicationCommitDto;
import org.laot.searchManage.service.IDatasourceApplicationService;
import org.laot.searchManage.vo.DatasourceApplicationPageVo;
import org.springframework.http.HttpRequest;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;


/**
 * 数据源申请单接口
 * @author laoT
 * @date 2024/1/24
 */

@Slf4j
@Api(tags = "数据源申请单接口")
@RestController
@RequestMapping("/datasource/application")
public class DatasourceApplicationController {

    @Resource
    private IDatasourceApplicationService datasourceApplicationService;
    @Resource
    private UserUtils userUtils;

    @PostMapping("/commit")
    @ApiOperation("提交申请单")
    public BaseResponse<String> commit(@RequestBody DatasourceApplicationCommitDto dto){
        datasourceApplicationService.commit(dto);
        return ResultUtils.success("提交成功");
    }


    @PostMapping("/page")
    @ApiOperation("页面查询")
    BaseResponse<Page<DatasourceApplicationPageVo>> page(@RequestBody PageRequest pageRequest){
        Page<DatasourceApplicationPageVo> returnList = datasourceApplicationService.pageInfo(pageRequest);
        return ResultUtils.success(returnList);
    }

    @PostMapping("/approve")
    @ApiOperation("审批")
    public BaseResponse<String> approve(@RequestBody DatasourceApplicationApproveDto datasourceApplicationApproveDto, HttpServletRequest request){
        //拿到用户名
        User user = userUtils.getLoginUser(request);
        datasourceApplicationService.approve(datasourceApplicationApproveDto,user.getUserName());
        return ResultUtils.success("审批成功");
    }






}
